using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


/// <summary>
/// The CurrencyCodeTableManager class is responsible for managing BO.CurrencyCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class CurrencyCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all CurrencyCodeTable objects in the database.
/// </summary>
/// <returns>A list with all CurrencyCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static CurrencyCodeTableList GetList(){
return CurrencyCodeTableDB.GetList();
}

/// <summary>
/// Gets a single CurrencyCodeTable from the database without its data.
/// </summary>
/// <param name="currencyCodeKey">The CurrencyCode of the CurrencyCodeTable in the database.</param>
/// <returns>A CurrencyCodeTable object when the CurrencyCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static CurrencyCodeTable GetItem(Int16 currencyCodeKey){
return GetItem(currencyCodeKey, false);
}

/// <summary>
/// Gets a single CurrencyCodeTable from the database.
/// </summary>
/// <param name="currencyCodeKey">The CurrencyCode of the CurrencyCodeTable in the database.</param>
/// <param name="getCurrencyCodeTableRecords">Determines whether to load all associated CurrencyCodeTable records as well.</param>
/// <returns>
/// A CurrencyCodeTable object when the CurrencyCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static CurrencyCodeTable GetItem(Int16 currencyCodeKey, bool getCurrencyCodeTableRecords){
CurrencyCodeTable myCurrencyCodeTable = CurrencyCodeTableDB.GetItem(currencyCodeKey);
if (myCurrencyCodeTable != null && getCurrencyCodeTableRecords){
myCurrencyCodeTable.teacherSalaryTables = TeacherSalaryTableDB.GetListByCurrencyCode(currencyCodeKey);
}
return myCurrencyCodeTable;
}

/// <summary>
/// Saves a CurrencyCodeTable in the database.
/// </summary>
/// <param name="myCurrencyCodeTable">The CurrencyCodeTable instance to save.</param>
/// <returns>The new CurrencyCode if the CurrencyCodeTable is new in the database or the existing CurrencyCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static Int16 Save(CurrencyCodeTable myCurrencyCodeTable)
{
using (TransactionScope myTransactionScope = new TransactionScope()){
    Int16 currencyCodeTableCurrencyCode = CurrencyCodeTableDB.Save(myCurrencyCodeTable);
foreach (TeacherSalaryTable myTeacherSalaryTable in myCurrencyCodeTable.teacherSalaryTables){
myTeacherSalaryTable.CurrencyCode = currencyCodeTableCurrencyCode;
TeacherSalaryTableDB.Save(myTeacherSalaryTable);
}

//  Assign the CurrencyCodeTable its new (or existing CurrencyCode).
myCurrencyCodeTable.CurrencyCodeKey = myCurrencyCodeTable.CurrencyCodeKey;

myTransactionScope.Complete();

return currencyCodeTableCurrencyCode;
}
}

/// <summary>
/// Deletes a CurrencyCodeTable from the database.
/// </summary>
/// <param name="myCurrencyCodeTable">The CurrencyCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(CurrencyCodeTable myCurrencyCodeTable){
return CurrencyCodeTableDB.Delete(myCurrencyCodeTable.CurrencyCodeKey);
}

#endregion


public static short currencyCodeKey { get; set; }
  }

